package tw.spring.demo.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import tw.spring.demo.model.AjaxResponse;
import tw.spring.demo.model.Article;

/**
 * @author: 陈艺博
 * @date: 2021-02-06 17:23
 * @description: 测试MockMvc用例
 **/
@Slf4j
@RestController
@RequestMapping("/mock")
public class MockController {

    @PostMapping(value = "/articles")
    public AjaxResponse addMock(@RequestBody Article article) {
        log.info("saveArticle: " + article);
        return AjaxResponse.success(article);
    }

    @PostMapping(value = "/articles/v1")
    public AjaxResponse addMockV1(@RequestParam String title, @RequestParam String author) {
        Article article = new Article();
        article.setTitle(title);
        article.setAuthor(author);
        log.info("saveArticle: " + article);
        return AjaxResponse.success(article);
    }
    @GetMapping(value = "/articles")
    public AjaxResponse getMock(@RequestParam Long id) {
        log.info("id: " + id);
        return AjaxResponse.success(id);
    }
}